package top.toptimus.dto.material.materialIndex;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Map;

/**
 * 原辅料DTO
 */
@NoArgsConstructor
@AllArgsConstructor
@Data
public class MaterialDTO {
    private String material_id;           //物料ID
    private String material_category;     //原辅料类别
    private String material_type_cd;    //
    private String material_name_cn;      //原辅料中文名称
    private String material_code;         //原辅料代码
    private String material_composition;  //物料成分
    private String material_spec;         //物料幅宽
    private String material_spec_unit_cd; //规格单位CD
    private String material_unit_cd;      //货品单位CD
    private String material_year;         //原辅料年份
    private String material_color;        //原辅料颜色
    private String material_season;       //原辅料季节CD
    private String material_gram_weight;  //原辅料克重
    private String material_weave;       //原辅料织法
    private String material_sample;      //样品物料区分
    private String material_source;      //原辅料来源(1:客供物料 2:自采物料)
    private String material_thread_count; //原辅料纱支密度
    private String material_style;       //原辅料风格
    private String material_other1;       //面料供应商名称
    private String material_other3;       //保留3
    private String material_other4;       //保留4
    private String remarks;                //备注
    private String delete_flag;                //是否删除（0未删除，1已删除。）
    private String create_date;                //生成时间

    /**
     * 辅料保存构造函数
     */
    public MaterialDTO(
            String material_code
            , String material_name_cn
            , String material_spec
            , String material_composition
    ) {
        this.material_code = material_code;
        this.material_name_cn = material_name_cn;
        this.material_spec = material_spec;
        this.material_composition = material_composition;
        this.material_sample = "0";
        this.material_source = "MATERIAL_SOURCE-CUSTOMER";
    }

    public MaterialDTO(
            String material_id,
            String material_category,
            String material_name_cn,
            String material_code,
            String material_composition,
            String material_spec,
            String material_spec_unit_cd,
            String material_unit_cd,
            String material_year,
            String material_color,
            String material_season,
            String material_gram_weight,
            String material_weave,
            String material_sample,
            String material_source,
            String material_thread_count,
            String material_style,
            String material_other1,
            String material_other3,
            String material_other4,
            String remarks,
            String delete_flag,
            String create_date
    ) {
        this.material_id = material_id;
        this.material_category = material_category;
        this.material_name_cn = material_name_cn;
        this.material_code = material_code;
        this.material_composition = material_composition;
        this.material_spec = material_spec;
        this.material_spec_unit_cd = material_spec_unit_cd;
        this.material_unit_cd = material_unit_cd;
        this.material_year = material_year;
        this.material_color = material_color;
        this.material_season = material_season;
        this.material_gram_weight = material_gram_weight;
        this.material_weave = material_weave;
        this.material_sample = material_sample;
        this.material_source = material_source;
        this.material_thread_count = material_thread_count;
        this.material_style = material_style;
        this.material_other1 = material_other1;
        this.material_other3 = material_other3;
        this.material_other4 = material_other4;
        this.remarks = remarks;
        this.delete_flag = delete_flag;
        this.create_date = create_date;
    }

    /**
     * 数据放在map集合中
     *
     * @param map resultset
     */
    public MaterialDTO(Map<String, Object> map) {
        this.material_id = map.containsKey("material_id") && (map.get("material_id") != null) ? map.get("material_id").toString() : "";
        this.material_category = map.containsKey("material_category") && (map.get("material_category") != null) ? map.get("material_category").toString() : "";
        this.material_name_cn = map.containsKey("material_name_cn") && (map.get("material_name_cn") != null) ? map.get("material_name_cn").toString() : "";
        this.material_code = map.containsKey("material_code") && (map.get("material_code") != null) ? map.get("material_code").toString() : "";
        this.material_composition = map.containsKey("material_composition") && (map.get("material_composition") != null) ? map.get("material_composition").toString() : "";
        this.material_spec = map.containsKey("material_spec") && (map.get("material_spec") != null) ? map.get("material_spec").toString() : "";
        this.material_spec_unit_cd = map.containsKey("material_spec_unit_cd") && (map.get("material_spec_unit_cd") != null) ? map.get("material_spec_unit_cd").toString() : "";
        this.material_unit_cd = map.containsKey("material_unit_cd") && (map.get("material_unit_cd") != null) ? map.get("material_unit_cd").toString() : "";
        this.material_year = map.containsKey("material_year") && (map.get("material_year") != null) ? map.get("material_year").toString() : "";
        this.material_color = map.containsKey("material_color") && (map.get("material_color") != null) ? map.get("material_color").toString() : "";
        this.material_season = map.containsKey("material_season") && (map.get("material_season") != null) ? map.get("material_season").toString() : "";
        this.material_gram_weight = map.containsKey("material_gram_weight") && (map.get("material_gram_weight") != null) ? map.get("material_gram_weight").toString() : "";
        this.material_weave = map.containsKey("material_weave") && (map.get("material_weave") != null) ? map.get("material_weave").toString() : "";
        this.material_sample = map.containsKey("material_sample") && (map.get("material_sample") != null) ? map.get("material_sample").toString() : "";
        this.material_source = map.containsKey("material_source") && (map.get("material_source") != null) ? map.get("material_source").toString() : "";
        this.material_thread_count = map.containsKey("material_thread_count") && (map.get("material_thread_count") != null) ? map.get("material_thread_count").toString() : "";
        this.material_style = map.containsKey("material_style") && (map.get("material_style") != null) ? map.get("material_style").toString() : "";
        this.material_other1 = map.containsKey("material_other1") && (map.get("material_other1") != null) ? map.get("material_other1").toString() : "";
        this.material_other3 = map.containsKey("material_other3") && (map.get("material_other3") != null) ? map.get("material_other3").toString() : "";
        this.material_other4 = map.containsKey("material_other4") && (map.get("material_other4") != null) ? map.get("material_other4").toString() : "";
        this.remarks = map.containsKey("remarks") && (map.get("remarks") != null) ? map.get("remarks").toString() : "";
        this.delete_flag = map.containsKey("delete_flag") && (map.get("delete_flag") != null) ? map.get("delete_flag").toString() : "";
        this.create_date = map.containsKey("material_other4") && (map.get("material_other4") != null) ? map.get("material_other4").toString() : "";

    }


    /**
     * 数据放在map集合中
     *
     * @param resultSet resultset
     */
    public MaterialDTO(ResultSet resultSet) throws SQLException {
        this.material_id = resultSet.getString("MATERIAL_ID");
        this.material_code = resultSet.getString("MATERIAL_CODE");
        this.material_name_cn = resultSet.getString("MATERIAL_NAME_CN");
        this.material_spec = resultSet.getString("MATERIAL_SPEC");
        this.material_composition = resultSet.getString("material_composition");
        this.remarks = resultSet.getString("remarks");
    }
//    public MaterialDTO(){
//        Map<String, Object> map = new HashMap<>();
//        this.material_id = map.get("material_id").toString();
//        map.put("","");
//
//    }


    /**
     * 插入数据到i_material_p表中
     * TODO
     *
     * @return insert语句
     */
    public String MaterialInsertSql() {
        return "INSERT INTO `fragsmart-erp`.`i_material_p` (\n" +
                "	`MATERIAL_ID`,\n" +
                "	`MATERIAL_CATEGORY`,\n" +
                "	`MATERIAL_NAME_CN`,\n" +
                "	`MATERIAL_CODE`,\n" +
                "	`MATERIAL_COMPOSITION`,\n" +
                "	`MATERIAL_SPEC`,\n" +
                "	`MATERIAL_SPEC_UNIT_CD`,\n" +
                "	`MATERIAL_UNIT_CD`,\n" +
                "	`MATERIAL_YEAR`,\n" +
                "	`MATERIAL_COLOR`,\n" +
                "	`MATERIAL_SEASON`,\n" +
                "	`MATERIAL_GRAM_WEIGHT`,\n" +
                "	`MATERIAL_WEAVE`,\n" +
                "	`MATERIAL_SAMPLE`,\n" +
                "	`MATERIAL_SOURCE`,\n" +
                "	`MATERIAL_THREAD_COUNT`,\n" +
                "	`MATERIAL_STYLE`,\n" +
                "	`MATERIAL_OTHER1`,\n" +
                "	`MATERIAL_OTHER3`,\n" +
                "	`MATERIAL_OTHER4`,\n" +
                "	`REMARKS` \n" +
                ")\n" +
                "VALUES\n" +
                "	(\n" +
                "		" + this.material_id + "+,\n" +
                "		" + this.material_category + ",\n" +
                "		" + this.material_name_cn + ",\n" +
                "		" + this.material_code + ",\n" +
                "		" + this.material_composition + ",\n" +
                "		" + this.material_spec + ",\n" +
                "		" + this.material_spec_unit_cd + ",\n" +
                "		" + this.material_unit_cd + ",\n" +
                "		" + this.material_year + ",\n" +
                "		" + this.material_color + ",\n" +
                "		" + this.material_season + ",\n" +
                "		" + this.material_gram_weight + ",\n" +
                "		" + this.material_weave + ",\n" +
                "		" + this.material_sample + ",\n" +
                "		" + this.material_source + ",\n" +
                "		" + this.material_thread_count + ",\n" +
                "		" + this.material_style + ",\n" +
                "		" + this.material_other1 + ",\n" +
                "		" + this.material_other3 + ",\n" +
                "		" + this.material_other4 + ",\n" +
                "	'REMARKS'" + this.remarks + "" +
                " \n" +
                "	);";
    }
}
